package windows.propertyWindow
{
import windows.*;
	import flash.display.Sprite;
	import com.bit101.components.RadioButton;
	import flash.events.Event;
	import com.bit101.components.Window;
	import com.bit101.components.Label;
	import com.bit101.components.InputText;
	import com.bit101.components.CheckBox;
	import flash.events.MouseEvent;
	import baseitems.Base;
	
	/**
	 * перенести потом в отдельный пэкэдж
	 * проперти только для лэйера
	 * @author artem.kolesnikov 
	 */
	public class PropertyLayerView extends Sprite
	{
		private var yPosition:int = 160;
		
		private var alignView3:AlignView;
		private var wstack:RadioButton;
		private var hstack:RadioButton;
		private var copyChildrenSize:CheckBox;
		
		public function PropertyLayerView() 
		{
			wstack = new RadioButton(this, 10, yPosition, "w stack", false, onPropertyChanged); 
			hstack = new RadioButton(this, 65, yPosition, "h stack", true, onPropertyChanged); 
			yPosition += 20;
			copyChildrenSize = new CheckBox(this, 10, yPosition, "copy size", onPropertyChanged); 
			yPosition += 10;
			
			alignView3 = new AlignView("stack align");
			alignView3.x = 10;
			alignView3.y = yPosition;
			alignView3.groupName = "pstack_position";
			alignView3.addEventListener(MouseEvent.CLICK, onPropertyChanged);
			addChild(alignView3);
		}
		
		private function refresh():void {
			var obj:Base = Controller.instance.selectedObject;
			wstack.selected = obj.wstack;
			hstack.selected = obj.hstack;
			copyChildrenSize.enabled = !(obj.percentWidthEnabled || obj.percentHeightEnabled);
			copyChildrenSize.selected = obj.copySize;
			// уберем чек и проставим сразу в настройках что мол неа
			if (!copyChildrenSize.enabled) {
				if (Controller.instance.haveSelected) {
					copyChildrenSize.enabled = false;
					copyChildrenSize.selected = false;
					Controller.instance.selectedObject.copySize = false;
				}
			}
			alignView3.setAlign(obj.stackAlign);
		}
		
		private function onPropertyChanged(event:MouseEvent):void {
			if (Controller.instance.haveSelected) {
				Controller.instance.selectedObject.wstack = wstack.selected;
				Controller.instance.selectedObject.hstack = hstack.selected;
				Controller.instance.selectedObject.copySize = copyChildrenSize.selected;
				Controller.instance.selectedObject.stackAlign = alignView3.getAlign();
			}
		}
		
		override public function set visible(value:Boolean) :void {
			super.visible = value;
			if (value) {
				refresh();
			}
		}
	}
}